package o;

import androidx.annotation.Nullable;
import java.io.IOException;

public abstract class adr {
    protected final i ˊ;
    protected final c ˋ;
    private final int ˎ;
    @Nullable
    protected b ॱ;

    public static final class a {
    }

    protected static class b {
        private long ʻ;
        private final long ˊ;
        private long ˋ;
        private final long ˎ;
        private long ˏ;
        private final long ॱ;
        private long ॱॱ;
        private long ᐝ;

        protected static long ˏ(long j, long j2, long j3, long j4, long j5, long j6) {
            if (1 + j4 >= j5 || 1 + j2 >= j3) {
                return j4;
            }
            long j7 = (long) (((float) (j - j2)) * (((float) (j5 - j4)) / ((float) (j3 - j2))));
            return anr.ˎ(((j7 + j4) - j6) - (j7 / 20), j4, j5 - 1);
        }

        protected b(long j, long j2, long j3, long j4, long j5, long j6, long j7) {
            this.ˊ = j;
            this.ॱ = j2;
            this.ˏ = j3;
            this.ˋ = j4;
            this.ॱॱ = j5;
            this.ᐝ = j6;
            this.ˎ = j7;
            this.ʻ = ˏ(j2, j3, j4, j5, j6, j7);
        }

        private long ˎ() {
            return this.ॱॱ;
        }

        private long ˊ() {
            return this.ᐝ;
        }

        private long ˋ() {
            return this.ॱ;
        }

        private long ॱ() {
            return this.ˊ;
        }

        private void ˎ(long j, long j2) {
            this.ˏ = j;
            this.ॱॱ = j2;
            ʻ();
        }

        private void ˋ(long j, long j2) {
            this.ˋ = j;
            this.ᐝ = j2;
            ʻ();
        }

        private long ˏ() {
            return this.ʻ;
        }

        private void ʻ() {
            this.ʻ = ˏ(this.ॱ, this.ˏ, this.ˋ, this.ॱॱ, this.ᐝ, this.ˎ);
        }
    }

    public static class c implements aea {
        private final long ʻ;
        private final long ʼ;
        private final long ˊ;
        private final long ˋ;
        private final d ˎ;
        private final long ˏ;
        private final long ॱ;

        public c(d dVar, long j, long j2, long j3, long j4, long j5, long j6) {
            this.ˎ = dVar;
            this.ˋ = j;
            this.ˊ = j2;
            this.ॱ = j3;
            this.ˏ = j4;
            this.ʻ = j5;
            this.ʼ = j6;
        }

        public boolean ˊ() {
            return true;
        }

        public o.aea.a ˏ(long j) {
            return new o.aea.a(new aeh(j, b.ˏ(this.ˎ.ˋ(j), this.ˊ, this.ॱ, this.ˏ, this.ʻ, this.ʼ)));
        }

        public long g_() {
            return this.ˋ;
        }

        public long ˎ(long j) {
            return this.ˎ.ˋ(j);
        }
    }

    protected interface d {
        long ˋ(long j);
    }

    public static final class e implements d {
        public long ˋ(long j) {
            return j;
        }
    }

    protected interface i {
        j ˏ(adv o_adv, long j, a aVar) throws IOException, InterruptedException;

        void ॱ();
    }

    public static final class j {
        public static final j ˋ = new j(-3, -9223372036854775807L, -1);
        private final long ˎ;
        private final int ˏ;
        private final long ॱ;

        private j(int i, long j, long j2) {
            this.ˏ = i;
            this.ˎ = j;
            this.ॱ = j2;
        }

        public static j ˎ(long j, long j2) {
            return new j(-1, j, j2);
        }

        public static j ˏ(long j, long j2) {
            return new j(-2, j, j2);
        }

        public static j ˏ(long j) {
            return new j(0, -9223372036854775807L, j);
        }
    }

    protected adr(d dVar, i iVar, long j, long j2, long j3, long j4, long j5, long j6, int i) {
        this.ˊ = iVar;
        this.ˎ = i;
        this.ˋ = new c(dVar, j, j2, j3, j4, j5, j6);
    }

    public final aea ˋ() {
        return this.ˋ;
    }

    public final void ˏ(long j) {
        if (this.ॱ == null || this.ॱ.ॱ() != j) {
            this.ॱ = ˊ(j);
        }
    }

    public final boolean ॱ() {
        return this.ॱ != null;
    }

    public int ˋ(adv o_adv, adz o_adz, a aVar) throws InterruptedException, IOException {
        i iVar = (i) amm.ॱ(this.ˊ);
        while (true) {
            b bVar = (b) amm.ॱ(this.ॱ);
            long ˏ = bVar.ˎ();
            long ॱ = bVar.ˊ();
            long ˊ = bVar.ˏ();
            if (ॱ - ˏ <= ((long) this.ˎ)) {
                ˏ(false, ˏ);
                return ˊ(o_adv, ˏ, o_adz);
            } else if (!ˊ(o_adv, ˊ)) {
                return ˊ(o_adv, ˊ, o_adz);
            } else {
                o_adv.ˏ();
                j ˏ2 = iVar.ˏ(o_adv, bVar.ˋ(), aVar);
                switch (ˏ2.ˏ) {
                    case -3:
                        ˏ(false, ˊ);
                        return ˊ(o_adv, ˊ, o_adz);
                    case -2:
                        bVar.ˎ(ˏ2.ˎ, ˏ2.ॱ);
                        break;
                    case -1:
                        bVar.ˋ(ˏ2.ˎ, ˏ2.ॱ);
                        break;
                    case 0:
                        ˏ(true, ˏ2.ॱ);
                        ˊ(o_adv, ˏ2.ॱ);
                        return ˊ(o_adv, ˏ2.ॱ, o_adz);
                    default:
                        throw new IllegalStateException("Invalid case");
                }
            }
        }
    }

    protected b ˊ(long j) {
        return new b(j, this.ˋ.ˎ(j), this.ˋ.ˊ, this.ˋ.ॱ, this.ˋ.ˏ, this.ˋ.ʻ, this.ˋ.ʼ);
    }

    protected final void ˏ(boolean z, long j) {
        this.ॱ = null;
        this.ˊ.ॱ();
        ˊ(z, j);
    }

    protected void ˊ(boolean z, long j) {
    }

    protected final boolean ˊ(adv o_adv, long j) throws IOException, InterruptedException {
        long ˊ = j - o_adv.ˊ();
        if (ˊ < 0 || ˊ > 262144) {
            return false;
        }
        o_adv.ॱ((int) ˊ);
        return true;
    }

    protected final int ˊ(adv o_adv, long j, adz o_adz) {
        if (j == o_adv.ˊ()) {
            return 0;
        }
        o_adz.ˊ = j;
        return 1;
    }
}
